﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">

    private string c_dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            if (Request.QueryString["c_dt"] != null)
            {
                c_dt = Request.QueryString["c_dt"];
                this.Label1.Text = "(" + c_dt + ")";
                this.Label2.Text = "(" + c_dt + ")";
                this.DataList_DataTable();
                ViewState["c_dt"] = c_dt;

                this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + c_dt;
            }
            else 
            {
                this.HyperLink2.NavigateUrl = "CalendarArrangeShow.aspx?c_dt=" + DateTime.Now.ToShortDateString().Replace("-", "/");
            }

            
        }
    }

    private void DataList_DataTable()
    {
        User curLoginUser = (User) Session["user"];
        DateTime curDt = DateTime.Parse(c_dt);
        UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
        List<UserCalendarArrangetb> list = ucatbService.findCurDateAllByUserLoginNameAndCurDate(
            curLoginUser.LoginName, curDt);
        DataTable dt = new DataTable();
        dt.Columns.Add("CalendarArrangeStartTime", typeof(string));
        dt.Columns.Add("CalendarArrangeEndTime", typeof(string));
        dt.Columns.Add("CalendarArrangeId", typeof(string));
        dt.Columns.Add("CalendarArrangeTitle", typeof(string));
        dt.Columns.Add("CalendarArrangeContent", typeof(string));
        dt.Columns.Add("CalendarArrangeType", typeof(string));
        dt.Columns.Add("CalendarArrangeDate", typeof(string));
        dt.Columns.Add("CalendarArrangeState", typeof(string));
        if(list != null && list.Count > 0)
        {
            foreach(UserCalendarArrangetb ucatb in list)
            {
                DataRow dr = dt.NewRow();
                dr["CalendarArrangeStartTime"] = ucatb.CalendarArrangeStartTime;
                dr["CalendarArrangeEndTime"] = ucatb.CalendarArrangeEndTime;
                dr["CalendarArrangeId"] = ucatb.CalendarArrangeId.ToString();
                dr["CalendarArrangeTitle"] = ucatb.CalendarArrangeTitle;
                dr["CalendarArrangeContent"] = ucatb.CalendarArrangeContent;
                dr["CalendarArrangeType"] = ucatb.CalendarArrangeType.Equals("1") ? "工作事务" : "个人事务";
                dr["CalendarArrangeDate"] = ucatb.CalendarArrangeDate.ToShortDateString();
                string state = "";
                DateTime startTime = DateTime.Parse(ucatb.CalendarArrangeDate.ToShortDateString() + " " + ucatb.CalendarArrangeStartTime);
                DateTime endTime = DateTime.Parse(ucatb.CalendarArrangeDate.ToShortDateString() + " " + ucatb.CalendarArrangeEndTime);
                if(startTime < DateTime.Now && DateTime.Now < endTime)
                {
                    state = "<font color='green'><b>进行中</b></font>";
                }
                else if(endTime > DateTime.Now)
                {
                    state = "<font color='blue'><b>未至</b></font>";
                }
                else
                {
                    state = "<font color='red'><b>已过期</b></font>";
                }
                dr["CalendarArrangeState"] = state;
                dt.Rows.Add(dr);
            }
            this.DataList1.DataSource = dt.DefaultView;
            this.DataList1.DataBind();
        }
        else
        {
            this.DataList1.DataSource = null;
            this.DataList1.DataBind();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if(ViewState["c_dt"] != null)
        {
            c_dt = (string) ViewState["c_dt"];
        }
        Response.Redirect("CalendarAppend.aspx?c_dt=" + c_dt);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("ArrangeIndex.aspx");
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string caid = ((HtmlInputHidden) e.Item.FindControl("Hidcaid")).Value.Trim();
            ((LinkButton) e.Item.FindControl("LbtDisplay")).Attributes.Add("caid", caid);
            ((LinkButton) e.Item.FindControl("LbtEdit")).Attributes.Add("caid", caid);
            ((LinkButton) e.Item.FindControl("LbtDel")).Attributes.Add("caid", caid);
            ((LinkButton) e.Item.FindControl("LbtDel")).Attributes.Add("onclick", "javascript:return confirm('您确认删除当前事务吗？')");
        }
    }

    protected void LbtEdit_Click(object sender, EventArgs e)
    {
        int caid = int.Parse(((LinkButton) sender).Attributes["caid"]);
        if(ViewState["c_dt"] != null)
        {
            c_dt = (string) ViewState["c_dt"];
        }
        Response.Redirect("CalendarEdit.aspx?ca_id=" + caid + "&c_dt=" + c_dt);
    }

    protected void LbtDel_Click(object sender, EventArgs e)
    {
        if(ViewState["c_dt"] != null)
        {
            c_dt = (string) ViewState["c_dt"];
        }
        int caid = int.Parse(((LinkButton) sender).Attributes["caid"]);
        UserCalendarArrangetbService ucatbService = new UserCalendarArrangetbService();
        ucatbService.delCalendarArrangeInfoById(caid);
        this.DataList_DataTable();
        DateTime curDt = DateTime.Parse(c_dt);
        User curLoginUser = (User) Session["user"];
        List<UserCalendarArrangetb> list = ucatbService.findCurDateAllByUserLoginNameAndCurDate(curLoginUser.LoginName, curDt);
        if(list == null)
        {
            list = new List<UserCalendarArrangetb>();
        }
        CalendarArrangeInfos cainfos = CalendarArrangeInfos.instance();
        cainfos.Cainfos.Remove(curLoginUser.LoginName);
        cainfos.Cainfos.Add(curLoginUser.LoginName, list);
        ViewState["c_dt"] = c_dt;
    }

    protected void LbtDisplay_Click(object sender, EventArgs e)
    {
        if(ViewState["c_dt"] != null)
        {
            c_dt = (string) ViewState["c_dt"];
        }
        int caid = int.Parse(((LinkButton) sender).Attributes["caid"]);
        Response.Redirect("CalendarInfo.aspx?ca_id=" + caid + "&c_dt=" + c_dt);
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

   <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />
   <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>

      <style type="text/css">
<!--
html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
-->
</style>
</head>
<body>
    <form id="form1" runat="server">
        <div  class="sub_right_top">
            <!--滑动门-->
    <div class="hdm_header" >
     <div class="tb1_off" id="tab1"><h2 class="h2_icon">
     <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/CalendarArrange/ArrangeIndex.aspx">日程安排</asp:HyperLink>
     </h2></div>
     <div class="tb1_on" id="tab2"><h2 class="h2_icon">
      <asp:HyperLink ID="HyperLink2" runat="server">今日日程</asp:HyperLink>
     </h2></div>
      <div class="tb1_off" id="tab3"><h2 class="h2_icon">
            <asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/CalendarArrange/CalendarArrangeDemand.aspx">日程查询</asp:HyperLink>
      </h2></div>
     <div class="clear"></div>
   </div>
   <div class="hdm_footer">
   <div id="tb1_2_content" class="cont01_word">      
         <div class="fabu_gg_title">&nbsp;新建事务<asp:Label ID="Label2" runat="server" Text="Label" Width="166px"></asp:Label></div>
         <div class="new_ggtz">
            <asp:ImageButton ID="Button1" runat="server" ImageUrl="~/images/new_all_but.gif" OnClick="Button1_Click" />
       </div>
       <div class="fabu_gg_title">&nbsp;管理日程安排<asp:Label ID="Label1" runat="server" Text="Label" Width="169px"></asp:Label></div> 

        <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
                            <HeaderTemplate>
                                <table width="99%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse; ">
                                    <tr>
                                        <td>事务标题</td>
                                        <td>开始时间</td>
                                        <td>结束时间</td>
                                        <td>事务类型</td>
                                        <td>事务内容</td>
                                        <td>状态</td>
                                        <td>操作</td>
                                    </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                    <tr>
                                        <td >
                                                <asp:Label ID="LblTitle" runat="server" Text='<%# Eval("CalendarArrangeTitle") %>' ></asp:Label>
                                        </td>
                                        <td align="center" >
                                                <asp:Label ID="LblStartTime" runat="server" Text='<%# Eval("CalendarArrangeStartTime") %>' ></asp:Label>
                                        </td>
                                        <td>
                                                <asp:Label ID="LblEndTime" runat="server" Text='<%# Eval("CalendarArrangeEndTime") %>'></asp:Label>
                                        </td>
                                        <td>
                                                <asp:Label ID="LblType" runat="server" Text='<%# Eval("CalendarArrangeType") %>'
                                                    ></asp:Label>
                                        </td>
                                        <td>
                                                <asp:Label ID="LblContent" runat="server" Text='<%# Eval("CalendarArrangeContent").ToString().Length > 20 ? Eval("CalendarArrangeContent").ToString().Trim().Substring(0,20) + "..." : Eval("CalendarArrangeContent").ToString().Trim()%>'
                                                    ></asp:Label>
                                        </td>
                                        <td align="center" >
                                                <asp:Label ID="LblState" runat="server" Text='<%# Eval("CalendarArrangeState") %>'></asp:Label>
                                                <input id="Hidcaid" runat="server" type="hidden" value='<%# Eval("CalendarArrangeId") %>' />
                                        </td>
                                        <td>
                                            <asp:LinkButton ID="LbtDisplay" runat="server" Font-Underline="False" ForeColor="Teal" OnClick="LbtDisplay_Click"><font style="font-size:12px">查看</font></asp:LinkButton>
                                            <asp:LinkButton ID="LbtEdit" runat="server" Font-Underline="False" ForeColor="Teal" OnClick="LbtEdit_Click"><font style="font-size:12px">编辑</font></asp:LinkButton>
                                            <asp:LinkButton ID="LbtDel" runat="server" Font-Underline="False"
                                                ForeColor="Teal" OnClick="LbtDel_Click"><font style="font-size:12px">删除</font></asp:LinkButton></td>
                                    </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
             </div>
         </div>
     </div>
    </form>
</body>
</html>
